// Copyright (c) Microsoft. All rights reserved.

namespace Microsoft.KernelMemory;

/// <summary>
/// Extensions of the TagCollection class
/// </summary>
public static class TagCollectionExtensions
{
    /// <summary>
    /// Return a copy of the tag collection, de-referenced from the source.
    /// </summary>
    /// <param name="tagCollection">Tag collection to clone</param>
    /// <returns>New tag collection instance</returns>
    public static TagCollection Clone(this TagCollection tagCollection)
    {
        var clone = new TagCollection();
        tagCollection.CopyTo(clone);
        return clone;
    }

    /// <summary>
    /// Add special tag for synthetic data generated by the pipeline.
    /// </summary>
    /// <param name="tagCollection">Tag collection to update</param>
    /// <param name="value">Value of the synthetic tag, e.g. 'summary', 'whiteboard', etc.</param>
    /// <returns>The tag collection instance</returns>
    public static TagCollection AddSyntheticTag(this TagCollection tagCollection, string value)
    {
        ArgumentNullExceptionEx.ThrowIfNullOrWhiteSpace(value, nameof(value), "The tag value cannot be empty");
        tagCollection.Add(Constants.ReservedSyntheticTypeTag, value);
        return tagCollection;
    }
}
